package Exception;

public class Login {
    public String name = "admin";
    public String password = "123456abc@";


    public void logIn(String name, String password){
        boolean flag = true;
        try {

            if(!name.equals(this.name)){
                throw new NameErrorException("用户名错误:" + name);
            }else if(!password.equals(this.password)){
                throw new PasswordErrorException("密码错误:" + password);
            }

        }catch (NameErrorException e){
            e.printStackTrace();
            System.out.println("捕获到用户名错误异常");
            flag = false;
        }catch (PasswordErrorException e){
            e.printStackTrace();
            System.out.println("捕获到密码错误异常");
            flag = false;
        }

        if(flag){
            System.out.println("登录成功!");
        }

    }

    public static void main(String[] args) {
        Login login = new Login();
        login.logIn("admin", "1236abc@");
    }
}
